//package cn.nfwx.tv.adapter;
//
//import android.content.Context;
//import android.support.annotation.NonNull;
//import android.support.v7.widget.RecyclerView;
//import android.text.TextUtils;
//import android.view.LayoutInflater;
//import android.view.MotionEvent;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.ImageView;
//import android.widget.TextView;
//
//import com.lcodecore.tkrefreshlayout.utils.DensityUtil;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import cn.nfwx.tv.R;
//import cn.nfwx.tv.conts.Contants;
//import cn.nfwx.tv.model.QpopChannel;
//import cn.nfwx.tv.model.TvChannel;
//import cn.nfwx.tv.util.GlideUtil;
//
///**
// * Created by zb.liu on 2017/11/1.
// */
//public class ChannelAdapter extends RecyclerView.Adapter<ChannelAdapter.ChannelViewHolder> {
//    private final String TAG = ChannelAdapter.class.getSimpleName();
//    private Context mContext;
//    private onItemClickListener onItemClickListener;
//    private int selectedPosition = -5;
//    private List<Object> mlist = new ArrayList<>();
//    private boolean _init;
//
//    public ChannelAdapter(Context context) {
//        mContext = context;
//    }
//
//    @Override
//    public ChannelViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        View view = LayoutInflater.from(mContext).inflate(R.layout.activity_channel_item, parent, false);
//        return new ChannelViewHolder(view);
//    }
//
//    @Override
//    public void onBindViewHolder(final ChannelViewHolder holder, int position) {
//        holder.iv_channel_placeholder.setVisibility(View.GONE);
//        if (_init) {
//            holder.iv_channel_placeholder.setVisibility(View.VISIBLE);
//            return;
//        }
//        Object object = mlist.get(position);
//        if (object instanceof QpopChannel.DataBean.Channel) {
//            QpopChannel.DataBean.Channel channel = (QpopChannel.DataBean.Channel) object;
//            GlideUtil.loadRoundImage(mContext, Contants.Qpop_url + channel.getImgUrl(), holder.channelImageView, GlideUtil.ScaleType.DEFAULT);
//            holder.tvChannelName.setText(channel.getTitle());
//
//            if (selectedPosition == position) {
//                if (TextUtils.isEmpty(channel.getCurrent())) {
//                    holder.tvProgramName.setText("正在直播");
//                } else {
//                    holder.tvProgramName.setText(channel.getCurrent());
//                }
//                holder.channelImageView.setSelected(true);
//                holder.channelImageView.getLayoutParams().width = DensityUtil.dp2px(holder.channelImageView.getContext(), 42);
//                holder.channelImageView.getLayoutParams().height = DensityUtil.dp2px(holder.channelImageView.getContext(), 42);
//                //holder.tv_btn.setSelected(true);
//                holder.tvProgramName.setVisibility(View.VISIBLE);
//                holder.tvProgramName.setSelected(true);
//                holder.tvProgramName.setTextColor(mContext.getResources().getColor(R.color.program_text));
//            } else {
//                holder.channelImageView.setSelected(false);
//                //holder.tv_btn.setSelected(false);
//                holder.tvProgramName.setVisibility(View.GONE);
//                holder.tvProgramName.setSelected(false);
//                // holder.tv_btn.setBackgroundResource(R.drawable.shape_corner_up);
//            }
//            holder.itemView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    int position = holder.getLayoutPosition();
//                    onItemClickListener.onOnItemClick(view, position);
//                    selectedPosition = position;
//                    notifyItemChanged(selectedPosition);
//                }
//            });
//        } else if (object instanceof TvChannel) {
//            TvChannel tvChannel = (TvChannel) object;
//            GlideUtil.loadRoundImage(mContext, tvChannel.getLogo(), holder.channelImageView, GlideUtil.ScaleType.DEFAULT);
//            holder.tvChannelName.setText(tvChannel.getName());
//
//            if (selectedPosition == position) {
//                if (tvChannel.getPlayingProgram() != null) {
//                    if (TextUtils.isEmpty(tvChannel.getPlayingProgram().getProgram_name())) {
//                        holder.tvProgramName.setText("正在直播");
//                    } else {
//                        holder.tvProgramName.setText(tvChannel.getPlayingProgram().getProgram_name());
//                    }
//                } else {
//                    if (TextUtils.isEmpty(tvChannel.getProgram_name())) {
//                        holder.tvProgramName.setText("正在直播");
//                    } else {
//                        holder.tvProgramName.setText(tvChannel.getProgram_name());
//                    }
//                }
//                holder.channelImageView.setSelected(true);
//                holder.channelImageView.getLayoutParams().width = DensityUtil.dp2px(holder.channelImageView.getContext(), 42);
//                holder.channelImageView.getLayoutParams().height = DensityUtil.dp2px(holder.channelImageView.getContext(), 42);
//                //holder.tv_btn.setSelected(true);
//                holder.tvProgramName.setVisibility(View.VISIBLE);
//                holder.tvProgramName.setSelected(true);
//                holder.tvProgramName.setTextColor(mContext.getResources().getColor(R.color.program_text));
//            } else {
//                holder.channelImageView.setSelected(false);
//                //holder.tv_btn.setSelected(false);
//                holder.tvProgramName.setVisibility(View.GONE);
//                holder.tvProgramName.setSelected(false);
//                // holder.tv_btn.setBackgroundResource(R.drawable.shape_corner_up);
//            }
//            holder.itemView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    int position = holder.getLayoutPosition();
//                    onItemClickListener.onOnItemClick(view, position);
//                    selectedPosition = position;
//                    notifyItemChanged(selectedPosition);
//                }
//            });
//        }
//    }
//
//    public void setSelected(int position) {
//        this.selectedPosition = position;
//    }
//
//    @Override
//    public int getItemCount() {
//        return mlist.size();
//    }
//
//    /**
//     * 更新正在播放的节目
//     *
//     * @param position
//     * @param channel
//     */
//    public void notifyItemChanged(int position, TvChannel channel) {
//        if (mlist.isEmpty() || channel == null) {
//            notifyItemChanged(position);
//        } else {
//            for (Object o : mlist) {
//                if (o instanceof TvChannel) {
//                    TvChannel tvChannel = (TvChannel) o;
//                    if (tvChannel.getGid().equals(channel.getGid())) {
//                        tvChannel.setPlayingProgram(channel.getPlayingProgram());
//                        break;
//                    }
//                }
//            }
//            notifyItemChanged(position);
//        }
//    }
//
//    public void setNewData(List newData) {
//        _init = false;
//        mlist.clear();
//        mlist.addAll(newData);
//        notifyDataSetChanged();
//    }
//
//    /**
//     * 初始化信息，队长说要
//     */
//    public void initData() {
//        mlist.clear();
//        _init = true;
//        for (int i = 0; i < 10; i++) {
//            TvChannel livemode = new TvChannel();
//            mlist.add(livemode);
//        }
//        notifyDataSetChanged();
//    }
//
//
//    class ChannelViewHolder extends RecyclerView.ViewHolder {
//        private ImageView channelImageView;
//        private TextView tvChannelName;
//        private TextView tvProgramName;
//        private ImageView iv_channel_placeholder;
//        //private RelativeLayout tv_btn;
//
//        public ChannelViewHolder(View itemView) {
//            super(itemView);
//            channelImageView = itemView.findViewById(R.id.channel_image);
//            tvChannelName = itemView.findViewById(R.id.tv_channel_name);
//            tvProgramName = itemView.findViewById(R.id.tv_program_name);
//            iv_channel_placeholder = itemView.findViewById(R.id.iv_channel_placeholder);
//            //tv_btn = itemView.findViewById(R.id.tv_btn);
//        }
//    }
//
//    public interface onItemClickListener {
//        //条目被点击时触发的回调
//        void onOnItemClick(View view, int position);
//
//    }
//
//    public void setOnItemClickListener(onItemClickListener onItemClickListener) {
//        this.onItemClickListener = onItemClickListener;
//    }
//}
